
/**
 * #info
 *@author   wuwg
 *@createTime   2018/03/20
 *@updateTime    2018/05/07
 *@description  tooltip  component   提示框组件
 */

/**
 * #item
 *
 * @type        aty-tooltip
 * @cn          提示框
 * @menu        通知
 * @stPlugin    true
 * @stContainer true
 * @mixins      [./components/components/base/popper.js]
 */

import config from '../../../config/config.js'

// components

// directives
import TransferDom from '../../../directives/transfer-dom.js'
// mixins
import Popper from '../../base/popper.js'
// prefix
const prefixCls = config.prefix + '-tooltip'
// module
const module = {
  name: config.prefix + '-tooltip',
  mixins: [Popper],
  directives: { TransferDom },
  components: { },
  props: {
    /**
     * #property
     *
     * @name    placement
     * @cn      提示框出现的位置
     * @type    list
     * @options  [ top, top-start, top-end ,
     * bottom ,bottom-start, bottom-end,
     * left , left-start , left-end ,
     * right, right-start, right-end]
     * @value    bottom
     * @description  提示框出现的位置，取值为
     * [ top, top-start, top-end ,
     * bottom ,bottom-start, bottom-end,
     * left , left-start , left-end ,
     * right, right-start, right-end]中的其中一个
     */
    placement: {
      validator (value) {
        return Artery.isOneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end'])
      },
      default: 'bottom'
    },
    /**
     * #property
     *
     * @name        content
     * @cn          提示框中的内容
     * @type        string,number
     * @description  提示框中显示的内容
     */
    content: {
      type: [String, Number],
      default: ''
    },
    /**
     * #property
     *
     * @name        delay
     * @cn          延迟显示，单位毫秒
     * @type        number
     * @value       100
     * @description 延迟显示，单位毫秒
     */
    delay: {
      type: Number,
      default: 100
    },

    /**
     * #property
     *
     * @name    disabled
     * @cn      是否禁用
     * @type    boolean
     * @value   false
     * @description 是否禁用提示
     */
    disabled: {
      type: Boolean,
      default: false
    },
    /**
     * #property
     *
     * @name    always
     * @cn      是否总是可见
     * @type    boolean
     * @value   false
     * @description 是否总是可见
     */
    always: {
      type: Boolean,
      default: false
    },
    /**
     * #property
     *
     * @name    controlled
     * @cn      鼠标离开是否关闭tooltip
     * @type    boolean
     * @value   false
     * @description controlled=true时，当鼠标离开，该tooltip不关闭，controlled=false时关闭，默认controlled=false;
     *   // under this prop,Tooltip will not close when mouseleave
     */
    controlled: {
      type: Boolean,
      default: false
    },
    /**
     * #property
     *
     * @name    transfer
     * @cn      是否穿梭
     * @type    boolean
     * @value   true
     * @bind   must
     * @description 是否穿梭，弹出部分以body为父,默认true
     */
    transfer: {
      type: Boolean,
      default: true
    },
    /**
     * #property
     *
     * @name    popperClass
     * @cn      弹出框的样式名称
     * @type    string
     * @description 弹出框的样式名称
     */
    popperClass: {
      type: String
    }
  },
  data () {
    return {
      prefixCls: prefixCls,
      scope: {
        className: config.prefix + '-tooltip'
      }
    }
  },
  watch: {
    content () {
      this.updatePopper()
    }
  },
  computed: {
    currentPopperClass () {
      return [prefixCls + '-popper', this.popperClass]
    }
  },
  methods: {
    handleShowPopper () {
      if (this.timeout) clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        this.visible = true
      }, this.delay)
    },
    handleClosePopper () {
      if (this.timeout) {
        clearTimeout(this.timeout)
        if (!this.controlled) {
          this.timeout = setTimeout(() => {
            this.visible = false
          }, 100)
        }
      }
    },
    setExpectedState () {

    }
  },
  updated () { },
  created () {},
  mounted () {
    if (this.always) {
      this.updatePopper()
    }
  }
}
export default module
